﻿@model IEnumerable<AvaliacaoOnline.Data.Avaliacao>

@{
    ViewBag.Title = "Avaliação Online - Avaliações";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@section head{
<script type="text/javascript">
    $(function () {
        $("select[name='IdCliente']").bind('change', function () {
            $('#formCliente').submit();
        });

        $("#grid tr:odd td").css("background-color", "white");
        $("#grid tr:even td").css("background-color", "transparent");
    });
    excluir = function (obj) {
        $.showMessage({
            message: "Deseja realmente excluir a avaliação, todas as questões também serão excluidas?",
            buttons: {
                "Sim": function () { $(obj).parent().submit(); },
                "Não": function () { $(this).dialog('close'); }
            }
        });
    }
    respostas = function (obj) {
        $(obj).parent().submit();
    }
</script>
@if(!String.IsNullOrWhiteSpace(ViewData["Message"] as string)){
<script type="text/javascript">
    $(function () {
        $.showMessage('@(Html.Raw(ViewData["Message"] as string))');
    });
</script>
}
}

<h3>Avaliações</h3>

<p style="text-align:left;">
@using (Html.BeginForm("List", "Avaliacao", FormMethod.Post, new {id = "formCliente"}))
{
    <text>
    Cliente:<br />
    @Html.DropDownList("IdCliente",(IEnumerable<SelectListItem>)ViewData["Clientes"])
    </text>
}
</p>
@if (Model.Count() == 0)
{
    <div class="quiet" style="width:100%; text-align:center;">Nenhum registro encontrado. (<a href="@Url.Action("Edit", "Avaliacao")">inserir avaliação</a>)</div>
    
}
else
{ 
<table border="0" cellpadding="0" cellspacing="0" style="width:100%" id="grid">
    <tr>
        <th style="width:55%">
            Titulo
        </th>
        <th style="width:10%">
            Início
        </th>
        <th style="width:10%">
            Fim
        </th>
        <th style="width:25%; text-align:center;">
            <a href="@Url.Action("Edit", "Avaliacao")">Inserir</a>
        </th>
    </tr>

    @foreach (var item in Model)
    {
    <tr>
        <td>
            @item.Titulo
        </td>
        <td>
            @item.DataInicial.ToString("dd/MM/yyyy")
        </td>
        <td>
            @item.DataFinal.ToString("dd/MM/yyyy")
        </td>
        <td style="text-align:center;">
            <form action="@Url.Action("Edit", "Avaliacao")" method="post" style="display:inline;">
                <a href="#" onclick="$(this).parent().submit();">Editar</a>
                <input type="hidden" name="Id" value="@item.Id" />
                &nbsp;&nbsp;|&nbsp;&nbsp;
            </form>
            <form action="@Url.Action("Delete", "Avaliacao")" method="post" style="display:inline;">
                <a href="#" onclick="excluir(this);">Excluir</a>
                <input type="hidden" name="IdAvaliacao" value="@item.Id" />
                <input type="hidden" name="IdCliente" value="@item.IdCliente" />
                &nbsp;&nbsp;|&nbsp;&nbsp;
            </form>
            <form action="@Url.Action("RespostasPorAvaliacao", "Relatorio")" method="post" style="display:inline;">
                <a href="#" onclick="respostas(this);">Respostas</a>
                <input type="hidden" name="IdAvaliacao" value="@item.Id" />
            </form>
        </td>
    </tr>
    }
</table>
}